﻿namespace EFS.RC.Presences.Controls.Lync.Presences
{

	public class PresenceGroupProperties
	{
		public System.String groupName;

		public System.Double windowHeight = -1;
		public System.Double windowWidth = -1;

		public System.Double leftPosition = -1;
		public System.Double topPosition = -1;

		public System.Windows.WindowState windowState = System.Windows.WindowState.Normal;

		public PresenceGroupProperties()
		{
		}

		public PresenceGroupProperties(System.String settingString)
		{
			System.String[] properties = settingString.Split(new System.Char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);

			groupName = properties[0];

			windowHeight = System.Double.Parse(properties[1]);
			windowWidth = System.Double.Parse(properties[2]);

			leftPosition = System.Double.Parse(properties[3]);
			topPosition = System.Double.Parse(properties[4]);

			switch (properties[5])
			{
				case "Normal":
					windowState = System.Windows.WindowState.Normal;
					break;
				case "Maximized":
					windowState = System.Windows.WindowState.Maximized;
					break;
				case "Minimized":
					windowState = System.Windows.WindowState.Minimized;
					break;
			}
		}

		public System.String GetSaveString()
		{
			return groupName + '|' + windowHeight + '|' + windowWidth + '|' +
				leftPosition + '|' + topPosition + '|' + windowState.ToString();
		}
	}

	public partial class PresenceWindow : System.Windows.Window
	{
		public PresenceGroupProperties properties = null;

		public PresenceWindow()
		{
			InitializeComponent();
		}

		public PresenceWindow(PresenceGroupProperties groupProperties)
		{
			InitializeComponent();

			this.properties = groupProperties;

			//set window properties
			if (properties.windowHeight != -1) Height = properties.windowHeight;
			if (properties.windowHeight != -1) Width = properties.windowWidth;
			if (properties.topPosition != -1) Top = properties.topPosition;
			if (properties.leftPosition != -1) Left = properties.leftPosition;

			if (properties.windowState != System.Windows.WindowState.Normal) WindowState = properties.windowState;

			if (!properties.groupName.Equals("")) this.headerMain.Text = properties.groupName;

			//show
			this.Show();
		}

		public System.String SaveProperties()
		{
			properties.windowHeight = Height;
			properties.windowWidth = Width;
			properties.leftPosition = Left;
			properties.topPosition = Top;
			properties.windowState = WindowState;

			return properties.GetSaveString();
		}
	}
}
